using System;
using UnityEngine;

[Serializable]
[RequireComponent(typeof(LineRenderer))]
public class KhanQuang : MonoBehaviour
{
	private LineRenderer line;

	private Transform tr;

	private Vector3[] positions;

	private Vector3[] directions;

	private int i;

	private float timeSinceUpdate;

	private Material lineMaterial;

	private float lineSegment;

	private int currentNumberOfPoints;

	private bool allPointsAdded;

	public int numberOfPoints;

	public float updateSpeed;

	public float riseSpeed;

	public float spread;

	private Vector3 tempVec;

	public KhanQuang()
	{
		currentNumberOfPoints = 2;
		numberOfPoints = 10;
		updateSpeed = 0.25f;
		riseSpeed = 0.25f;
		spread = 0.2f;
	}

	public void Start()
	{
		tr = transform;
		line = (LineRenderer)GetComponent(typeof(LineRenderer));
		lineMaterial = line.material;
		lineSegment = 1f / (float)numberOfPoints;
		positions = new Vector3[numberOfPoints];
		directions = new Vector3[numberOfPoints];
		line.SetVertexCount(currentNumberOfPoints);
		for (i = 0; i < currentNumberOfPoints; i++)
		{
			tempVec = getSmokeVec();
			directions[i] = tempVec;
			positions[i] = tr.position;
			line.SetPosition(i, positions[i]);
		}
	}

	public void Update()
	{
		timeSinceUpdate += Time.deltaTime;
		if (!(timeSinceUpdate <= updateSpeed))
		{
			timeSinceUpdate -= updateSpeed;
			if (!allPointsAdded)
			{
				currentNumberOfPoints++;
				line.SetVertexCount(currentNumberOfPoints);
				tempVec = getSmokeVec();
				directions[0] = tempVec;
				positions[0] = tr.position;
				line.SetPosition(0, positions[0]);
			}
			if (!allPointsAdded && currentNumberOfPoints == numberOfPoints)
			{
				allPointsAdded = true;
			}
			for (i = currentNumberOfPoints - 1; i > 0; i--)
			{
				tempVec = positions[i - 1];
				positions[i] = tempVec;
				tempVec = directions[i - 1];
				directions[i] = tempVec;
			}
			tempVec = getSmokeVec();
			directions[0] = tempVec;
		}
		for (i = 1; i < currentNumberOfPoints; i++)
		{
			tempVec = positions[i];
			tempVec += directions[i] * Time.deltaTime;
			positions[i] = tempVec;
			line.SetPosition(i, positions[i]);
		}
		positions[0] = tr.position;
		line.SetPosition(0, tr.position);
		if (allPointsAdded)
		{
			float x = lineSegment * (timeSinceUpdate / updateSpeed);
			Vector2 mainTextureOffset = lineMaterial.mainTextureOffset;
			mainTextureOffset.x = x;
			Vector2 vector2 = lineMaterial.mainTextureOffset = mainTextureOffset;
		}
	}

	public Vector3 getSmokeVec()
	{
		Vector3 vector = default(Vector3);
		vector.x = UnityEngine.Random.Range(10f, 0f);
		vector.y = UnityEngine.Random.Range(2f, 5f);
		vector.z = UnityEngine.Random.Range(-1f, 1f);
		vector.Normalize();
		vector *= spread;
		vector.x += riseSpeed;
		return vector;
	}

	public void Main()
	{
	}
}
